package com.newtouch.bxzs.business.train.controller;

import com.newtouch.bxzs.business.config.MyLog;
import com.newtouch.bxzs.business.train.model.bo.KnowledgeBaseBO;
import com.newtouch.bxzs.business.train.model.vo.KnowledgeBaseVO;
import com.newtouch.bxzs.business.train.model.vo.NewKnowledgeBaseVO;
import com.newtouch.bxzs.business.train.service.KnowledgeBaseService;
import com.newtouch.bxzs.common.base.response.BaseResponse;
import com.newtouch.bxzs.common.base.response.RespGenerator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 知识库控制器
 *
 * <p>
 * <b>History:</b>
 * <table border="1">
 * <tr>
 * <th>Date</th>
 * <th>Operator</th>
 * <th>Memo</th>
 * </tr>
 * <tr>
 * <td>2021/1/11 9:32</td>
 * <td>lingshouyi</td>
 * <td>Create</td>
 * </tr>
 * </table>
 *
 * @author lingshouyi
 * @version 1.0.0
 * @since 1.0.0
 */
@Api(tags = "知识库")
@RestController
@RequestMapping("/knowledgeBaseController")
@SuppressWarnings("unchecked")
public class KnowledgeBaseController {

	@Autowired
	private KnowledgeBaseService knowledgeBaseService;
	/**
	 * 静态变量：系统日志
	 */
	private static final Log logger = LogFactory.getLog(KnowledgeBaseController.class);

	@ApiOperation(value = "PC端查询知识库列表信息", notes = "查询所有知识库列表信息,可按照知识库标题模糊查询,分类查询,分类和标题结合查询")
	@PostMapping("/getKnowledgeBaseList")
	@MyLog(systemFunctionName = "知识库", systemFunctionUrl = "/knowledgeBaseController/getKnowledgeBaseList", userOperationType = 4, userOperationSummary = "PC端查询知识库列表信息")
	public BaseResponse<KnowledgeBaseBO> getKnowledgeBaseList(@RequestBody KnowledgeBaseVO knowledgeBaseVO) {
		return RespGenerator.returnOK(knowledgeBaseService.getKnowledgeBaseList(knowledgeBaseVO, false));
	}

	@ApiOperation(value = "APP端查询知识库列表信息", notes = "查询所有知识库列表信息,可按照知识库标题模糊查询,分类查询,分类和标题结合查询")
	@PostMapping("/getKnowledgeBaseListOnApp")
	@MyLog(systemFunctionName = "知识库", systemFunctionUrl = "/knowledgeBaseController/getKnowledgeBaseListOnApp", userOperationType = 4, userOperationSummary = "APP端查询知识库列表信息")
	public BaseResponse<KnowledgeBaseBO> getKnowledgeBaseListOnApp(@RequestBody KnowledgeBaseVO knowledgeBaseVO) {
		return RespGenerator.returnOK(knowledgeBaseService.getKnowledgeBaseList(knowledgeBaseVO, true));
	}

	@ApiOperation(value = "查看知识库详情信息", notes = "根据知识编号查看知识详情信息")
	@GetMapping("/getKnowledgeBaseDetail")
	@MyLog(systemFunctionName = "知识库", systemFunctionUrl = "/knowledgeBaseController/getKnowledgeBaseDetail", userOperationType = 4, userOperationSummary = "查看知识库详情信息")
	public BaseResponse<KnowledgeBaseBO> getKnowledgeBaseDetail(
			@RequestParam(value = "knowledgeBaseId") @ApiParam(value = "知识库id") String knowledgeBaseId) {
		logger.info("查看知识库详情信息");
		return RespGenerator.returnOK(knowledgeBaseService.getKnowledgeBaseDetail(knowledgeBaseId));
	}

	@ApiOperation(value = "新增或者修改知识库信息", notes = "新增或者修改知识库信息")
	@PostMapping("/modifyKnowledgeBase")
	@MyLog(systemFunctionName = "知识库", systemFunctionUrl = "/knowledgeBaseController/modifyKnowledgeBase", userOperationType = 5, userOperationSummary = "新增或者修改知识库信息")
	public BaseResponse<String> modifyKnowledgeBase(@RequestBody NewKnowledgeBaseVO newKnowledgeBaseVO) {
		return RespGenerator.returnOK(knowledgeBaseService.modifyKnowledgeBase(newKnowledgeBaseVO));
	}

	@ApiOperation(value = "发布/撤销知识库", notes = "发布/撤销知识库")
	@GetMapping("/changeKnowledgeBaseState")
	@MyLog(systemFunctionName = "知识库", systemFunctionUrl = "/knowledgeBaseController/changeKnowledgeBaseState", userOperationType = 2, userOperationSummary = "发布/撤销知识库")
	public BaseResponse<Integer> changeKnowledgeBaseState(
			@RequestParam(value = "knowledgeBaseId") @ApiParam(value = "知识库id") String knowledgeBaseId,
			@RequestParam(value = "publishStatus") @ApiParam(value = "发布状态：1-未发布；2-已发布；3-已结束；4-已取消；5-已撤销；") String publishStatus) {
		return RespGenerator.returnOK(knowledgeBaseService.changeKnowledgeBaseState(knowledgeBaseId, publishStatus));
	}

	@ApiOperation(value = "删除/批量删除知识库信息")
	@PostMapping("/deleteKnowledgeBase")
	@MyLog(systemFunctionName = "知识库", systemFunctionUrl = "/knowledgeBaseController/deleteKnowledgeBase", userOperationType = 3, userOperationSummary = "删除/批量删除知识库信息")
	public BaseResponse<Integer> deleteKnowledgeBase(
			@RequestBody @ApiParam(value = "知识库ID编号", required = true) List<String> knowledgeBaseIds) {
		logger.info("删除/批量删除知识库信息");
		return RespGenerator.returnOK(knowledgeBaseService.deleteKnowledgeBase(knowledgeBaseIds));
	}

}
